package com.example.testdemoutils.dynamic_data_source.service.impl;

import com.example.testdemoutils.dynamic_data_source.aop.DataSource;
import com.example.testdemoutils.dynamic_data_source.dao.SysUserDao;
import com.example.testdemoutils.dynamic_data_source.po.SysUserEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class DynamicDataSourceTestService {
    @Resource
    private SysUserDao sysUserDao;

    public void updateUser(Long id) {
        SysUserEntity user = new SysUserEntity();
        user.setUserId(id);
        user.setMobile("13500000000");
        sysUserDao.updateById(user);
    }


    @DataSource("slave1")
    public void updateUserBySlave1(Long id) {
        SysUserEntity user = new SysUserEntity();
        user.setUserId(id);
        user.setMobile("13500000001");
        sysUserDao.updateById(user);
    }

    @DataSource("slave2")
    public void updateUserBySlave2(Long id) {
        SysUserEntity user = new SysUserEntity();
        user.setUserId(id);
        user.setMobile("13500000002");
        sysUserDao.updateById(user);
    }
}

